<template>
	<view class="contents" :style="'height:'+screenHeight+'px;'">
		<view class="bodys">
			<view class="none" v-if="show">
				<view class="coent">
					<u-empty text="您已提交过满意度评价" mode="list" icon-size="200">
					</u-empty>
				</view>
			</view>
			<view class="conent" v-else>
				<view class="header">
					<span>满意度调查问卷</span>
				</view>
				<view class="" style="padding: 10rpx;">
					<span>&emsp;亲爱的同仁！感谢您参与此次满意度调查，您的意见将对其所从事的工作的总体态度，请认真填写。</span>
					<span>&emsp;请在提供的分值对应栏中打√，10分非常满意，8分满意，6分一般，0不满意。</span>
				</view>

				<view class="neiorng">
					<view class="">
						一、个人基本信息
					</view>
					<view class="datalist" v-for="(item,index) in datalist2" :key="index">
						<view class="list">
							<span style="color: red;">*&nbsp;</span>
							<span style="font-weight: bold;">{{item.ProTempCode}}.&nbsp;</span>
							<span>{{item.ProTemContent}}</span>
						</view>

						<view class="listb">
							<u-radio-group v-model="item.value"  iconPlacement="left">
								<u-radio v-for="(itema, indexa) in item.lists" @change="radioGroupChange2" :key="indexa"
									:name="itema.name">
									{{itema.name}}
								</u-radio>
							</u-radio-group>
						</view>
					</view>
				</view>


				<view class="neiorng">
					<view class="">
						二、问卷内容
					</view>
					<view class="datalist" v-for="(item,index) in datalist" :key="index">
						<view class="list">
							<span style="color: red;">*&nbsp;</span>
							<span style="font-weight: bold;">{{item.ProTempCode}}.&nbsp;</span>
							<span>{{item.ProTemContent}}</span>
						</view>
						<!-- @tap="ssss(index)" -->
						<view class="listb">
							<u-radio-group v-model="wjtx[index].value">
								<u-radio v-for="(itema, indexa) in wjtx[index].lists" @change="radioGroupChange"
									:key="indexa" :name="itema.name">
									{{itema.name}}
								</u-radio>
							</u-radio-group>
						</view>
					</view>
					<view class="jianyi">

						<u-field v-model="name" label="调查员" placeholder="请填写调查员">
						</u-field>
						<!-- <u-field v-model="occupation" label="签字" placeholder="请签字">
						</u-field>
						<u-field v-model="phone" label="调查日期" placeholder="请填写调查日期">
						</u-field> -->

					</view>

					<view style="width: 100%;display: flex;justify-content: center;padding:40rpx;">
						<view class="submit">
							<u-button type="primary" @click="submit">提交</u-button>
						</view>
					</view>
				</view>

			</view>

		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				occupation: '',
				phone: '',
				show: true,
				jianyival: '',
				screenHeight: getApp().globalData.screenHeight - 44,
				datalist: '',
				wjtx: [],
				datalist2: [{
						ProTempCode: 1,
						ProTemContent: "性别",
						lists: [{
								name: '男',
							//	disabled: false,
							},
							{
								name: '女',
							//	disabled: false,
							},

						],
						value: ""

					},
					{
						ProTempCode: 2,
						ProTemContent: "婚姻状态",
						lists: [{
								name: '已婚',
							//	disabled: false,
							},
							{
								name: '未婚',
								//disabled: false,
							},

						],
						value: ""

					},
					{
						ProTempCode: 3,
						ProTemContent: "年龄(按周岁计算)",
						lists: [{
								name: '20-30岁',
								//disabled: false,
							},
							{
								name: '31-40岁',
								//disabled: false,
							},
							{
								name: '41-50岁',
							//	disabled: false,
							},
							{
								name: '51岁以上',
							//	disabled: false,
							}

						],
						value: ""

					},
					{
						ProTempCode: 4,
						ProTemContent: "职务类别",
						lists: [{
								name: '一般员工',
							//	disabled: false,
							},
							{
								name: '医生',
							//	disabled: false,
							},
							{
								name: '护士',
								disabled: false,
							},
							{
								name: '管理人员',
							//	disabled: false,
							}

						],
						value: ""

					},
					{
						ProTempCode: 5,
						ProTemContent: "服务年限",
						lists: [{
								name: '1年以下',
							//	disabled: false,
							},
							{
								name: '1-3年',
							//	disabled: false,
							},
							{
								name: '3-5年',
								disabled: false,
							},
							{
								name: '5年以上', 
							//	disabled: false,
							}

						],
						value: ""

					}



				],
				text: ''
			}
		},
		onLoad() {
			this.list()
		},
		methods: {
			ssss(index) {
				console.log("满意度问题", index)
				if (this.text != '') {
					this.wjtx[index].value = this.text
				}
				console.log("wjtx", this.wjtx)
			},
			pinkProDetails() {
				console.log(this.wjtx)
				console.log(this.datalist)
				let temp3 = {
					prodetail: ''

				}
				let temp = []

				// let temp = `{"prodetail":[`
				for (let i = 0; i < this.wjtx.length; i++) {

					let le
					switch (this.wjtx[i].value) {
						case '非常满意':
							le = 10;
							break
						case '满意':
							le = 8;
							break
						case '一般':
							le = 6;
							break
						case '不满意':
							le = 0;
							break
					}

					temp.push({
						ProTempId: this.datalist[i].ProTempId,
						PF: le
					});





				}
				console.log(temp)
				temp3.prodetail = temp
				// temp = temp + `]}`

				return JSON.stringify(temp3)

			},
			submit() {
				uni.showLoading({
					title: '请稍后',
					mask: true
				});
				let sum = 0
				let item = this.wjtx
				console.log(this.wjtx)
				for (let i = 0; i < item.length; i++) {
					if (item[i].value == '非常满意') {
						sum += 10
					} else if (item[i].value == '满意') {
						sum += 8
					} else if (item[i].value == '一般') {
						sum += 6
					} else {
						sum += 0
					}
				}


				let ProDetails = this.pinkProDetails();
				// console.log("总分", sum)
				// return
				this.$request("ProblemTem", "Submit", {
					Content: "",
					ProDetails: ProDetails,
					ZPF: sum,
					Name: this.name,
					Phone: "",
					Work: this.datalist2[3].value,
					Protype: 3,
					Sex:this.datalist2[0].value,
					Marriage:this.datalist2[1].value,
					Age:this.datalist2[2].value,
					Fwnx:this.datalist2[4].value,

				}).then(res => {
					console.log("提交满意度问题", res)
					if (res.code == 1) {
						this.show = true
						uni.hideLoading();

					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					uni.hideLoading();
					console.log("err", err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});
				});
			},
			radioChange(e) {
				console.log(e);
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				console.log(66666666666666666666);
				console.log(e);
				this.text = e
				console.log("wsat", this.wjtx)

			},
			radioGroupChange2(e) {
				console.log(66666666666666666666);
				console.log(e);
				this.text = e
				console.log("wsat", this.datalist2)
			
			},
			list() {
				uni.showLoading({
					title: '请稍后',
					mask: true
				});
				this.$request("ProblemTem", "list", {
					protype: 3


				}).then(res => {
					// console.log("满意度问题", res)
					if (res.code == 1) {
						this.datalist = res.data
						this.wjtx = []
						let objet = {
							lists: [{
									name: '非常满意',
									value: 10
								},
								{
									name: '满意',
									value: 8
								},
								{
									name: '一般',
									value: 6
								}, {
									name: '不满意',
									value: 0
								},
							],
							value: '非常满意'
						}
						for (let i = 0; i < res.data.length; i++) {
							this.wjtx[i] = JSON.parse(JSON.stringify(objet))
						}
						console.log("this.wjtx", this.wjtx)
						console.log("this.datalist", this.datalist)
						this.show = false
						uni.hideLoading();

					} else {
						this.show = true
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					this.show = true
					uni.hideLoading();
					console.log("err", err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});
				});
			}
		}
	}
</script>

<style>
	@import './zhigongmanyidu.css';
</style>